package com.huanglj.taobaounion.view.customView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.huanglj.taobaounion.R;
import com.huanglj.taobaounion.base.BaseAppliaction;
import com.huanglj.taobaounion.ui.fragment.HomePagerFragment;
import com.lcodecore.tkrefreshlayout.IBottomView;

public class LoadButtonView implements IBottomView{

    private State mCurrentState = State.NONE;
    private View mLoadView;
    private View mEmptyView;
    private View mErrorView;
    private Context mContext = null;
    public LoadButtonView(Context context){
        mContext = context;
        initView(context);
    }



    private void initView(Context context) {
        mLoadView = LayoutInflater.from(context).inflate(R.layout.bottom_load_view, null, false);
        mErrorView = LayoutInflater.from(context).inflate(R.layout.bottom_error_view, null, false);
        mEmptyView = LayoutInflater.from(context).inflate(R.layout.bottom_empty_view, null, false);
        mCurrentState = State.NONE;
    }
    public void setState(State state){
        mCurrentState = state;
        getView();
    }

    @Override
    public View getView() {
        switch (mCurrentState){
            case NONE:
                return null;
            case EMPTY:
                return mEmptyView;
            case ERROR:
                return mErrorView;
            case LOADING:
                return mLoadView;
        }
        return null;
    }
    public State getCurrentState(){
        return mCurrentState;
    }

    @Override
    public void onPullingUp(float fraction, float maxBottomHeight, float bottomHeight) {

    }

    @Override
    public void startAnim(float maxBottomHeight, float bottomHeight) {

    }

    @Override
    public void onPullReleasing(float fraction, float maxBottomHeight, float bottomHeight) {

    }

    @Override
    public void onFinish() {
        if (mCurrentState == State.ERROR && mContext != null){
            Toast.makeText(mContext,"响应超时",Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void reset() {

    }

    public enum State{
        LOADING,EMPTY,ERROR,NONE,SUCCESS
    }

}
